<template>
	<div>
		<h1>Vuex Test</h1>
    <div>
      <router-link to="/vuex/shopcart">ShopCart链接</router-link>  &nbsp;&nbsp;
      <router-link to="/vuex/personal">Personal链接</router-link>
    </div>
    <br>
    <router-view></router-view>
  </div>
</template>

<script>
  // import {mapActions, mapMutations} from 'vuex'
	export default {
    name: 'vuexTest',

    mounted () {
      this.$store.dispatch('shopCart/getCartList')

      // 页面卸载前保存一下数据
      window.addEventListener('beforeunload', () => { // 当页面刷新时, 页面卸载前的事件回调
        sessionStorage.setItem('CART_LIST_KEY', 
          JSON.stringify(this.$store.state.shopCart.cartList))
      })
    },

    beforeDestroy() {
      window.removeEventListener('beforeunload')
    }
    
	}
</script>